<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                {if check_roles('admin/topic/create')}
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list layui-btn-primary" data-type="add"><i class="icon iconfont icon-tianjia"></i>添加记录</button>
                </div>
                {/if}
            </div>
        </div>

        <div class="layui-card-body">
            <table class="layui-table" style="margin-bottom: 20px">
                <thead>
                <tr>
                    <th>家长名称</th>
                    <th>联系方式</th>
                    <th>性别</th>
                    <th>注册时间</th>
                    <th>宝宝名称</th>
                    <th>性别</th>
                    <th>出生日期</th>
                    <th>父亲身高(cm)</th>
                    <th>母亲身高(cm)</th>
                    <th>期望身高(cm)</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>{$parent['nickname']}</td>
                    <td>{$parent['mobile']}</td>
                    <td>{$parent['gender'] == 2?'女':'男'}</td>
                    <td>{$parent['create_time']}</td>
                    <td>{$baby['name']}</td>
                    <td>{$baby['sex'] == 1?'女':'男'}</td>
                    <td>{$baby['birth']}</td>
                    <td>{$baby['farther_height']}</td>
                    <td>{$baby['mother_height']}</td>
                    <td>{$baby['hope_height']}</td>
                </tr>
                </tbody>
            </table>

            <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
            <script type="text/html" id="table-content-list">
                {if check_roles('admin/baby_grow_log/delete') }
                <a class="layui-btn layui-btn-normal-outline layui-btn-xs" lay-event="del">删除</a>
                {/if}
            </script>
        </div>
    </div>
</div>

<script>
    layui.use(['table','form'],function () {
        var $ = layui.$,table = layui.table,form = layui.form;
        //表单
        table.render({
            elem: '#LAY-app-content-list'
            ,url: "{:url('baby_grow_log/index')}?baby_id={$Request.get.baby_id}"
            ,cols: [[
                 {field: 'measure_time',  title: '测量时间'}
                ,{field: 'eat_cycle',  title: '食用周期（月）',width: 130}
                ,{field: 'height',  title: '身高（cm）',width: 110}
                ,{field: 'weight',  title: '体重（kg）',width: 110}
                ,{field: 'lebugao',  title: '乐补高食用量（粒）',minWidth: 160}
                ,{field: 'exercise_mode',  title: '运动方式'}
                ,{field: 'eat_habits',  title: '饮食习惯'}
                ,{field: 'note',  title: '注意事项'}
                ,{field: 'bone_age',  title: '骨龄',width: 110}
                ,{field: 'before_measure_time',  title: '既往测量时间'}
                ,{field: 'before_height',  title: '既往测量身高'}
                ,{field: 'report',  title: '测量报告'}
                ,{title: '操作', minWidth: 150, align: 'center', fixed: 'right', toolbar: '#table-content-list'}
            ]]
            ,page: true
            ,size: 'lg'
        });

        //搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            table.reload('LAY-app-content-list', {
                where: field
                ,page:1
            });
        });


        //工具条
        table.on('tool(LAY-app-content-list)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定删除？', function(index){
                    $.post("{:url('baby_grow_log/delete')}",{id:data.id},function (ret) {
                        if(ret.code == 0){
                            layer.msg(ret.msg,{icon:6,time:1000},function () {
                                layui.table.reload('LAY-app-content-list');
                            })
                        }else{
                            layer.msg(ret.msg,{icon:5,time:2000})
                        }
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type: 2
                    ,title: '编辑'
                    ,content: "{:url('topic/edit')}?id="+data.id
                    ,shadeClose: true
                    ,shade: 0.4
                    ,area: ['500px', '600px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            }
        });


        //顶部按钮
        var active = {
            add: function(){
                var index = layer.open({
                    type: 2
                    ,title: '添加'
                    ,content: "{:url('baby_grow_log/create')}?baby_id={$Request.get.baby_id}"
                    ,maxmin: false
                    ,area: ['500px', '600px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#form-submit");
                        submit.click();
                    }
                });
            }
        };

        $('.layui-btn.layuiadmin-btn-list').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });

</script>
